package com.zj.osm.view.map.offline

import org.osmdroid.tileprovider.cachemanager.CacheManager
import org.osmdroid.util.BoundingBox
import org.osmdroid.util.IterableWithSize
import org.osmdroid.util.MapTileArea
import org.osmdroid.util.MapTileAreaList
import java.text.DecimalFormat

/**
 * 版权：渤海新能 版权所有
 * @author zhujiang
 * 版本：1.5
 * 创建日期：2020/5/9
 * 描述：OsmDroid
 *
 */


/**
 * 转换文件大小
 *
 * @param num /
 * @return
 */
fun formatFileSize(num: Int): String {
    val fileS: Long = num.toLong()
    val df = DecimalFormat("#.00")
    var fileSizeString = ""
    val wrongSize = "0B"
    if (fileS == 0L) {
        return wrongSize
    }
    fileSizeString = when {
        fileS < 1024 -> {
            df.format(fileS.toDouble()).toString() + "KB"
        }
        fileS < 1048576 -> {
            df.format(fileS.toDouble() / 1024).toString() + "MB"
        }
        else -> {
            df.format(fileS.toDouble() / 1048576).toString() + "GB"
        }
    }
    return fileSizeString
}

fun formatFileSizes(num: Int): String {
    val fileS: Long = (num * 100 * 1024).toLong()
    val df = DecimalFormat("#.00")
    var fileSizeString = ""
    val wrongSize = "0B"
    if (fileS == 0L) {
        return wrongSize
    }
    fileSizeString = when {
        fileS < 1024 -> {
            df.format(fileS.toDouble()).toString() + "B"
        }
        fileS < 1048576 -> {
            df.format(fileS.toDouble() / 1024).toString() + "KB"
        }
        fileS < 1073741824 -> {
            df.format(fileS.toDouble() / 1048576).toString() + "MB"
        }
        else -> {
            df.format(fileS.toDouble() / 1073741824).toString() + "GB"
        }
    }
    return fileSizeString
}

//
//private fun getDownSize(zoom: Int): String {
//    var num = 0
//    for (index in 0..zoom) {
//        when (index) {
//            0 -> {
//                num += 35
//            }
//            1 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 35
//                num += size
//            }
//            2 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 40
//                num += size
//            }
//            3, 4, 5 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 50
//                num += size
//            }
//            6 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 75
//                num += size
//            }
//            7, 8, 9, 10 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 100
//                num += size
//            }
//            11, 12, 13 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 90
//                num += size
//            }
//            14, 15 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 80
//                num += size
//            }
//            16 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 60
//                num += size
//            }
//            17 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 45
//                num += size
//            }
//            18, 19 -> {
//                val size = (getTileNum(index) - getTileNum(index - 1)) * 30
//                num += size
//            }
//        }
//    }
//    return formatFileSize(num)
//}